package com.ll.dal.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ll.base.enums.ResultCodeEnum;
import com.ll.base.exception.CustomRunTimeException;
import com.ll.domain.pk.enums.PkResultEnum;
import com.ll.domain.pk.enums.PkStatusEnum;
import com.ll.domain.pk.enums.PkTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("pk_center_pk")
public class PkPO {
    @TableId(type= IdType.AUTO)
    private Long id;
    private Long tenantId;
    private Date ctime;
    private PkTypeEnum type;
    private PkStatusEnum status;
    private PkResultEnum result;
    private Long sourceId;
    private Long targetId;
    private Long refereeId;
    private String bizData;

    public boolean checkCanUpdateStatus(boolean throwExp){
        boolean result =  this.status == PkStatusEnum.发起中;
        if(!result && throwExp){
            throw new CustomRunTimeException(ResultCodeEnum.PK_STATUS_EXCEPTION);
        }
        return  result;
    }


    public boolean checkCanUpdateResult(boolean throwExp){
        boolean result =  this.result == PkResultEnum.未处理;
        if(!result && throwExp){
            throw new CustomRunTimeException(ResultCodeEnum.PK_RESULT_EXCEPTION);
        }
        return  result;
    }

    public boolean checkCanHandlerResult(Long refereeId, boolean throwExp){
        boolean result =  !refereeId.equals( this.sourceId ) && !refereeId.equals( this.targetId ) ;
        if(!result && throwExp){
            throw new CustomRunTimeException(ResultCodeEnum.PK_REFEREE_EXCEPTION);
        }
        return  result;
    }
}
